package org.mijia.dotsbox.core.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.mijia.dotsbox.core.EntityField;

public class Folder implements Entity {
	
	private String id;	
	private String name;
	private String parentId;
	
	public Folder() {
		id = name = parentId = "";
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	@EntityField (name = "name")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
		if (id == null || id.equals("")) {
			id = "" + System.nanoTime();
		}
	}

	@EntityField (name = "parentId", index = EntityField.INDEX_UNTOKENIZE)
	public String getParentId() {
		return parentId;
	}
	
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		
		if (obj instanceof String) {
			String folderName = (String) obj;
			return folderName.equalsIgnoreCase(name);
		}
		
		if (obj instanceof Folder) {
			Folder other = (Folder) obj;
			return id.equals(other.id);
		}
		
		return false;
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}
	
}
